package com.qf.demo;

import com.qf.pojo.Account;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import java.util.List;

/**
 * @ClassName Demo
 * @Description TODO
 * @Author 86181
 * @Date 2022/9/1 12:03
 * @Version 1.0
 **/
public class Demo {
    public static void main(String[] args) {
        JdbcTemplate jdbcTemplate = new JdbcTemplate();
        //创建数据源
        DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
        driverManagerDataSource.setDriverClassName("com.mysql.jdbc.Driver");
        driverManagerDataSource.setUrl("jdbc:mysql://localhost:3306/java1");
        driverManagerDataSource.setUsername("root");
        driverManagerDataSource.setPassword("");

        jdbcTemplate.setDataSource(driverManagerDataSource);

        //jdbcTemplate.execute("insert into account (name,money) values ('ls',8000.0),('wmz',9000.0),('zs',7800.0)");
        //jdbcTemplate.execute("delete from account where id=7");
//        int update=jdbcTemplate.update("delete from account where id=?",6);
//        System.out.println(update);

        List<Account> list
                = jdbcTemplate.query("select * from account where id > ? and money > ?", new BeanPropertyRowMapper<Account>(Account.class), 2, 500.0);
        for (Account account : list) {
            System.out.println(account);
        }

    }
}
